<%@ page language="java" import="java.util.*" isELIgnored="false" pageEncoding="UTF-8"%>
<%
String commonPath = request.getContextPath();
String commonBasePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+commonPath+"/";
%>
<!-- 基于jquery-validate-1.7的表单验证(说明：兼容性未调试完成) -->
<style type="text/css">
	input.error { border: 1px solid red; }
	label.error {
		background:url("<%=commonBasePath%>resources/images/wrong.gif") no-repeat 0px 0px;
		padding-left: 16px;
		padding-bottom: 2px;
		font-weight: bold;
		color: #EA5200;
	}
</style>
<script type="text/javascript" src="<%=commonBasePath%>resources/jquery/jquery-1.4.2.js"></script>
<%-- <script type="text/javascript" src="<%=commonBasePath%>resources/jquery-validate-1.7/lib/jquery.metadata.js"></script> --%>
<script type="text/javascript" src="<%=commonBasePath%>resources/jquery-validate-1.7/jquery.validate.min.js"></script>
<script type="text/javascript" src="<%=commonBasePath%>resources/common/validator.js"></script>
<script type="text/javascript" src="<%=commonBasePath%>resources/jquery-validate-1.7/additional-methods.js"></script>
<script type="text/javascript" src="<%=commonBasePath%>resources/jquery-validate-1.7/localization/messages_cn.js"></script>
<!-- 示例代码 -->
<script type="text/javascript">
	//设置默认属性
    $.validator.setDefaults({
    	debug: true,
    	submitHandler: function(form) {
        	submitForm();
        }
   	});
  	
  	$().ready(function() {
   		//用户名验证规则，只能由汉字、字母、数字、中划线组成
		jQuery.validator.addMethod("userName", function(value, element, param) {
			return this.optional(element) || isChinaOrNumbLettOrDash(value); //validator.js公共方法
		}, $.validator.format("Only can be composed of letters,numbers and dashes!"));
   		//表单验证设置
  		$("#userForm").validate({
  	    	errorElement: "div", // 使用"div"标签标记错误， 默认:"label"  
		   	wrapper: "li", // 使用"li"标签再把上边的errorELement包起来  
		    errorClass: "validate-error", // 错误提示的css类名"error"  
		    onsubmit: true, // 是否在提交是验证,默认:true  
		    onfocusout: true, // 是否在获取焦点时验证,默认:true  
		    onkeyup : true, // 是否在敲击键盘时验证,默认:true  
		    onclick: false, // 是否在鼠标点击时验证（一般验证checkbox,radiobox）
		    focusCleanup: false, // 当未通过验证的元素获得焦点时,并移除错误提示
  			rules: {
  				userID: {
  					required: true,
  					userName: true,
  					maxlength: 80
  				}
  			}, 
  			messages: {
  				userID: {
  					required: "User Name is not empty！"
  				}
  			}
  		});
  	});
</script>

